package com.geeklan.smart.ui.settings.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.geeklan.smart.data.model.AppProblem;
import com.geeklan.smart.data.model.VersionResponse;
import com.geeklan.smart.databinding.AdapterFunctionInfoItemBinding;
import com.geeklan.smart.databinding.LayoutCommonProblemItemBinding;
import com.geeklan.smart.ui.web.WebViewActivity;

import java.util.List;

public class ProblemAdapter extends RecyclerView.Adapter<ProblemAdapter.ViewHolder> {
    private Context mContext;
    private List<AppProblem> mData;

    public ProblemAdapter(Context context, List<AppProblem> data) {
        this.mData = data;
        this.mContext = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutCommonProblemItemBinding layoutCommonProblemItemBinding = LayoutCommonProblemItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(layoutCommonProblemItemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        AppProblem appProblem = mData.get(position);
        holder.mBinding.getRoot().setOnClickListener(v -> {
            WebViewActivity.startActivity(mContext, appProblem.getContentHtml(),appProblem.getTitle());
        });
        holder.mBinding.tvTitle.setText(appProblem.getTitle());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    // 自定义 ViewHolder
    static class ViewHolder extends RecyclerView.ViewHolder {
        LayoutCommonProblemItemBinding mBinding;

        public ViewHolder(@NonNull LayoutCommonProblemItemBinding mBinding) {
            super(mBinding.getRoot());
            this.mBinding = mBinding;
        }
    }
}
